﻿Public Class TaiKhoanDAO
    Public Shared Function LoadTaiKhoan() As DataTable
        Dim dt As DataTable = Nothing
        Dim strSQL As String = "select TK.tk_TenDangNhap, TK.tk_MatKhau, TK.tk_HoTen, TK.tk_DiaChi, TK.tk_CMND, GT.gt_GioiTinh, LTK.ltk_TenLoai from TaiKhoan TK, GioiTinh GT, LoaiTaiKhoan LTK where TK.tk_GioiTinh = GT.gt_ID and TK.tk_LoaiTK = LTK.ltk_ID"
        Dim dp As DataProvider = New DataProvider()
        dt = dp.ExecuteQuery(strSQL)
        Return dt
    End Function

    Public Shared Function GioiTinh() As DataTable
        Dim dt As DataTable = Nothing
        Dim strSQL As String = "select * from GioiTinh"
        Dim dp As DataProvider = New DataProvider()
        dt = dp.ExecuteQuery(strSQL)
        Return dt
    End Function

    Public Shared Function LoaiTaiKhoan() As DataTable
        Dim dt As DataTable = Nothing
        Dim strSQL As String = "select * from LoaiTaiKhoan"
        Dim dp As DataProvider = New DataProvider()
        dt = dp.ExecuteQuery(strSQL)
        Return dt
    End Function

    Public Shared Sub ThemTaiKhoan(ByVal _tk As TaiKhoan)
        Dim strSQL As String = "insert into TaiKhoan(tk_TenDangNhap,tk_MatKhau,tk_HoTen,tk_GioiTinh,tk_DiaChi,tk_CMND,tk_loaiTK) values ('" & _tk.m_strTenDangNhap & " ','" & _tk.m_strMatKhau & "','" & _tk.m_strHoTen & "','" & _tk.m_intGioiTinh & "','" & _tk.m_strDiaChi & "','" & _tk.m_strCMND & "','" & _tk.m_intLoaiTK & "')"
        Dim dp As DataProvider = New DataProvider()
        dp.ExecuteNonQuery(strSQL)
    End Sub

    Public Shared Function KiemtraTK(ByVal _tk As TaiKhoan)
        Dim dt As DataTable = Nothing
        Dim strSQL As String = "select tk_TenDangNhap from TaiKhoan where tk_TenDangNhap = '" + _tk.m_strTenDangNhap + "'"
        Dim dp As DataProvider = New DataProvider()
        dt = dp.ExecuteQuery(strSQL)
        Return dt
    End Function

    Public Shared Function XoaTK(ByVal _tk As TaiKhoan)
        Dim dt As DataTable = Nothing
        Dim strSQL As String = "delete from TaiKhoan where tk_TenDangNhap = '" + _tk.m_strTenDangNhap + "'"
        Dim dp As DataProvider = New DataProvider()
        dt = dp.ExecuteQuery(strSQL)
        Return dt
    End Function

    Public Shared Function CapNhatTK(ByRef _tk As TaiKhoan)
        Dim dt As DataTable = Nothing
        Dim strSQL As String = "UPDATE TaiKhoan set tk_MatKhau = '" & _tk.m_strMatKhau & "', tk_HoTen = '" & _tk.m_strHoTen & "',tk_GioiTinh = '" & _tk.m_intGioiTinh & "',tk_DiaChi = '" & _tk.m_strDiaChi & "',tk_CMND = '" & _tk.m_strCMND & "',tk_loaiTK = '" & _tk.m_intLoaiTK & "' where tk_TenDangNhap = '" & _tk.m_strTenDangNhap & "'"
        Dim dp As DataProvider = New DataProvider()
        dt = dp.ExecuteQuery(strSQL)
        Return dt
    End Function

End Class
